function checkHeader(resp) {
	code = resp.returnCode;
	if(code == 'NORMAL' || code == 'FAILED') {
		return true;
	} else if (code == 'ERROR') {
		alert('Sorry, system error, try a little late.');
	} else if (code == null) {
		alert('Sorry, unkonw error, try a little late.');
		window.location = BASE + "/";
	} 
	return false;
}

function addBase(url) {
	return BASE + url;
}
function addToken(data) {
	token = new Date().getTime();
	if (typeof(data) != "string") {
		$.extend(data, {'token': token});
	} else {
		data + '&token=' + token;
	}
	return data;
}

function postData(data, url, fn) {
	$.post(
		addBase(url),
		addToken(data),
		function(response) {
			if (checkHeader(response))
				fn(response);
		},
		"json"
	);
}

function advPostDate(data, url, fn, async) {
	$.ajax({
		type: "post",
		url: addBase(url),
		data: addToken(data),
		async: async && true,
		dataType: "json",
		success: function(response) {
			if (checkHeader(response))
				fn(response);
		}
	});
}

/*----------------------------------------------*/

function postCheckScode(request, fn) {
	postData(request, "/user/securityCode", fn);
}
function postCheckUser(request, fn) {
	postData(request, "/user/isExist", fn);
}
function postRegisterUser(request, fn) {
	postData(request, "/user/register", fn);
}
function postSearchUser(request, fn) {
	postData(request, "/admin/user/search", fn);
}
function postAddUser(request, fn) {
	postData(request, "/admin/user/add", fn);
}
function postUpdateUser(request, fn) {
	postData(request, "/admin/user/update", fn);
}
function postUpdateUserPwdByAdmin(request, fn) {
	postData(request, "/admin/user/updatePwd", fn);
}
function postUpdateUserPwdByUser(request, fn) {
	postData(request, "/user/updatePwd", fn);
}
function postDeleteUser(request, fn) {
	advPostDate(request, "/admin/user/delete", fn, true);
}